package com.itheima.servlet;

import com.itheima.pojo.Goods;
import com.itheima.service.GoodsService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
import java.util.UUID;

@WebServlet("/findAllGoods")
public class FindAllGoodsServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //1，创建GoodsService对象
        GoodsService goodsService = new GoodsService();
        //2，调用findAll方法查询所有数据
        List<Goods> goodsList = goodsService.findAll();
        //3，将数据封装到request域对象中
        request.setAttribute("goodsList",goodsList);
        //4，跳转到 WEB-INF/list.jsp 页面
        request.getRequestDispatcher("/WEB-INF/pages/list.jsp").forward(request,response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request,response);
    }
}
